package com.itheima;

import com.itheima.config.SpringConfig;
import com.itheima.dao.UserMapper;
import com.itheima.pojo.Staff;
import com.itheima.service.StaffService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;


//SpringJUnit4ClassRunner替代junit原生执行器
@RunWith(SpringJUnit4ClassRunner.class)
//加载注解配置类的
@ContextConfiguration(classes= SpringConfig.class)
public class AppTest {

    @Autowired
    private UserMapper userMapper;

    @Test
    public void queryAll(){
        List<Staff> list = userMapper.queryAll();
        for (Staff staff : list) {
            System.out.println("staff = " + staff);
        }
    }

    @Test
    public void insertNewUser(){
        Staff staff = new Staff();
        staff.setUsername("摸鱼大王");
        staff.setGender(0);
        staff.setIdcard("610112200002020");
        staff.setFromAddress("乌鲁木齐");
        staff.setToAddress("上海");
        staff.setStartTime(new Date());
        userMapper.insertNewUser(staff);
        //System.out.println("list = " + list);

    }


    @Test
    public void queryAllById(){
        Staff arr = userMapper.queryAllById(15L);
        System.out.println("arr = " + arr);
    }

    @Test
    public void deleteUserById(){
        userMapper.deleteUserById(19L);
    }
}
